import pylab as plt
import pandas as pd
import detect_segment
import detect_dp
fig = plt.figure(1,(10,8),dpi = 400)
legendlist = list()
def drawtraj_df(data):
    MMSIDATA = data['mmsi']
    SHIPSMMSI = list(set(MMSIDATA))
    shipcount = len(SHIPSMMSI)
    for i in range(shipcount):
        mmsi = SHIPSMMSI[i]
        ONESHIP = data.iloc[:, :][data[data.T.index[1]] == mmsi]  # 找出这艘船
        TRAJ_SEGMENT = list(set(ONESHIP["traj_segment"]))  # 这艘船轨迹段的set集合
        trajcount = len(TRAJ_SEGMENT)  # 这艘船轨迹段的数量
        for j in (TRAJ_SEGMENT):
            str_legend = str(mmsi)+":"+str(j)
            legendlist.append(str_legend)
            ONETRAJ = ONESHIP.iloc[:, :][ONESHIP[ONESHIP.T.index[9]] == j]
            x = ONETRAJ['longitude']
            y = ONETRAJ['latitude']
            plt.plot(x, y,'-o', markersize=1, linewidth=0.5)
    plt.show()

def drawtraj_list(trajlist):
    for i in range(len(trajlist)):
        onedata = pd.DataFrame(trajlist[i],
                               columns=['mmsi', 'longitude', 'latitude', 'cog', 'sog', 'Unixtime',
                                        'traj_segment'])
        x = onedata["longitude"]
        y = onedata["latitude"]
        plt.plot(x, y, '-o', markersize=3, linewidth=0.5)
    plt.show()

